package com.zyz.I_多线程.线程安全问题.同步代码块;

/**
 * @author: vick
 * @Date: 2025/3/22
 * @Description:
 * @version: 1.0
 */
public class Ticket {
    private int ticket = 10;

    public void sale() {
        if (ticket > 0) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "卖出了一张票，票号" + ticket--);
        }else {
            throw new RuntimeException("没有票了");
        }
    }
}
